﻿using FireStarterModeller.BO;
using Habanero.Testability;

namespace FireStarterModeller.Test.BO
{
    public class TestUtilsUIGridColumnInfo
    {

        public static BOTestFactory<UIGridColumnInfo> GetFactory()
        {
            var boTestFactory = BOTestFactoryRegistry.Instance.Resolve<UIGridColumnInfo>();
            //boTestFactory.SetValidValueGenerator(info => info.OrdinalPosition, typeof(ValidValueGeneratorIncrementalInt));
            return boTestFactory;
        }

        private static int OrdinalPosition = 1;
        /// <summary>
        /// Creates a new saved UIGridColumnInfo with a random value assigned to every property
        /// </summary>
        public static UIGridColumnInfo CreateSavedUIColumn()
        {
            UIGridColumnInfo uIGridColumn = CreateUnsavedValidUIColumn();
            uIGridColumn.Save();
            return uIGridColumn;
        }

        /// <summary>
        /// Creates a new unsaved UIGridColumnInfo with a random value assigned to every property
        /// </summary>
        public static UIGridColumnInfo CreateUnsavedValidUIColumn()
        {
/*            UIGridColumnInfo uIGridColumn = CreateUnsavedValidUIColumn_WNullGrid();
            uIGridColumn.UIGridID = TestUtilsShared.CreateSavedUIGridInfo().UIGridID;
            //uIGridColumn.OrdinalPosition = ++OrdinalPosition;
            return uIGridColumn;*/
            return GetFactory().CreateValidBusinessObject();
        }
	    
        /// <summary>
        /// Creates a new unsaved UIGridColumnInfo where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
        public static UIGridColumnInfo CreateUnsavedDefaultUIColumn()
        {
            UIGridColumnInfo uIGridColumn = new UIGridColumnInfo();
            return uIGridColumn;
        }

        public static UIGridColumnInfo CreateUnsavedValidUIColumn_WNullGrid()
        {
            UIGridColumnInfo uIGridColumn = new UIGridColumnInfo();
            uIGridColumn.Heading = TestUtilsShared.GetRandomString();
            uIGridColumn.PropertyName = TestUtilsDMProperty.CreateSavedDMProperty().PropertyName;
//            uIGridColumn.PropertyName = TestUtilsShared.GetRandomString();
            uIGridColumn.UIGridColumnControlType = TestUtilsUIGridColumnControlType.CreateSavedUIGridColumnControlType();
            uIGridColumn.Editable = TestUtilsShared.GetRandomBoolean();
            uIGridColumn.Width = TestUtilsShared.GetRandomInt();
            uIGridColumn.Alignment = TestUtilsShared.GetRandomString();
            uIGridColumn.Generated = TestUtilsShared.GetRandomBoolean();
            uIGridColumn.OrdinalPosition = GetFactory().GetValidPropValue(info => info.OrdinalPosition);
            return uIGridColumn;
            //return GetFactory().WithOutSingleRelationships().CreateValidBusinessObject();
        }
        public static UIGridColumnInfo CreateUnsavedValidUIColumn_WNullGrid_NullProperty()
        {
            UIGridColumnInfo uIGridColumn = new UIGridColumnInfo();
            uIGridColumn.Heading = TestUtilsShared.GetRandomString();
//            uIGridColumn.Property = TestUtilsDMProperty.CreateSavedDMProperty();
//            uIGridColumn.PropertyName = TestUtilsShared.GetRandomString();
            uIGridColumn.UIGridColumnControlType = TestUtilsUIGridColumnControlType.CreateSavedUIGridColumnControlType();
            uIGridColumn.Editable = TestUtilsShared.GetRandomBoolean();
            uIGridColumn.Width = TestUtilsShared.GetRandomInt();
            uIGridColumn.Alignment = TestUtilsShared.GetRandomString();
            uIGridColumn.Generated = TestUtilsShared.GetRandomBoolean();
            return uIGridColumn;
        }
    }
    public class BOTestFactoryUIGridColumnInfo: BOTestFactory<UIGridColumnInfo>
    {
        private static bool _vvGenSet = false;
        public BOTestFactoryUIGridColumnInfo()
        {
            SetOrdinalPositionGenerator();
        } 

        public BOTestFactoryUIGridColumnInfo(UIGridColumnInfo bo) : base(bo)
        {
            SetOrdinalPositionGenerator();
        }
        private void SetOrdinalPositionGenerator()
        {
            if (!_vvGenSet)
            {
                this.SetValidValueGenerator(info => info.OrdinalPosition, typeof(ValidValueGeneratorIncrementalInt));
                _vvGenSet = true;
            }
        }
    }
}